package controllers;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.Page;
import models.core.BaseAttrSpec;
import models.production.TaskSpec;
import play.data.Form;
import play.mvc.Controller;
import play.mvc.Result;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: hungdq
 * Date: 4/14/12
 * Time: 5:00 PM
 * To change this template use File | Settings | File Templates.
 */
public class ProcessTaskController extends Controller{
    public static Result create() {
        Form<TaskSpec> taskForm = form(TaskSpec.class);
        String atts = "att1,att2";

        taskForm.data().put("atts", atts);
        return ok(
                views.html.ProcessTask.create.render(taskForm, new ArrayList<BaseAttrSpec>())
        );
	
        //return ok(views.html.ProcessTask.create.render());
    }
    public static Result list(int page, String sortBy, String order, String filter) {
        Page<TaskSpec> one = TaskSpec.page(page, 10, sortBy, order, filter);
        System.out.println("aaaa" + one.getTotalRowCount());
        return ok(
                //views.html.ProcessTask.mylist.render(new Page<ProcessTask>())
                views.html.ProcessTask.mylist.render(one,sortBy, order, filter)
        );
    }
    public static Result save() {

        Page<TaskSpec> one = TaskSpec.page(1, 10, "name", "asc", null);
        System.out.println("aaaa" + one.getTotalRowCount());
        return ok(
                //views.html.ProcessTask.mylist.render(new Page<ProcessTask>())
                views.html.ProcessTask.mylist.render(one,"name", "asc", null)
        );
    }

    
    public static Result initData(){
        List<BaseAttrSpec> attributes = new ArrayList<BaseAttrSpec>();
        Ebean.beginTransaction();
        for (int i=0;i<20;i++){
            BaseAttrSpec attribute = new BaseAttrSpec();
            attribute.name= "attribute" + i;
            attributes.add(attribute);
            Ebean.save(attribute);
        }
        
        
        List<TaskSpec> tasks = new ArrayList<TaskSpec>();
        for(int i = 0; i< 20;i++){
            TaskSpec task = new TaskSpec();
            task.name = "task" + i;
            tasks.add(task);
            Ebean.save(task);
        }
        Ebean.commitTransaction();
        return ok("ok");
    }

}
